/******************************************************************************
  FILE        : ds1307.c
  PURPOSE     : Controlador para modulo de reloj 
  AUTHOR      : Antonio Vanegas P. (hpsaturn)
  FUNCTIONS   : 
  
  
  LANGUAGE    : ANSI-C
  ----------------------------------------------------------------------------
  HISTORY 
  
******************************************************************************/

#include "I2C.h"
#include "ds1307.h"

void DS1307_init (void){
  I2C_init();
}

//==========================
// write data one byte to
// DS1307
//==========================
void DS1307_write(unsigned char address, unsigned char data)
{
   short int status;
   I2C_start();
   I2C_tx_byte(0xd0);
   I2C_tx_byte(address);
   I2C_tx_byte(data);
   I2C_stop();
   I2C_start();
   status=I2C_tx_byte(0xd0);
   while(status==1)
   {
      I2C_start();
      status=I2C_tx_byte(0xd0);
   }
}

//==========================
// read data one byte from DS1307
//==========================
unsigned char DS1307_read(unsigned char address)
{
   unsigned char data;
   I2C_start();
   I2C_tx_byte(0xd0);
   I2C_tx_byte(address);
   I2C_start();
   I2C_tx_byte(0xd1);
   data=I2C_rx_byte(0);
   I2C_stop();
   return(data);
}
